package com.zenghus.service.impl;

import com.zenghus.dao.IndexDao;
import com.zenghus.demo.Index;
import com.zenghus.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zenghu
 * @date 2018/5/4 11:09
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    IndexDao indexDao;


    @Override
    public String getContext(String name) {
        return "Hello "+name;
    }

    @Override
    public List<Index> getIndex() {
        return indexDao.getIndex();
    }

    @Override
    public Integer add(Index index) {
        return indexDao.add(index);
    }

    @Override
    @Transactional
    public String testTransactional() {
        Index index=new Index();
        index.setName("123456");
        indexDao.add(index);

        Index i=new Index();
        i.setName("456789");
        indexDao.add(i);
        if(1==1){
            throw new NullPointerException("test Transactional");
        }
        return "";
    }
}
